using System;
using System.Collections.Generic;
using System.Text;

namespace DacTaHinhThuc
{
    /// <summary>
    /// class de anh xa tu loai du lieu sang tap hop va nguoc lai
    /// </summary>
    class Mapping
    {
        #region fields
        
        static private string[] m_arrSet = { "N", "Z", "R", "B" ,"C"};
        
        static private string[] m_arrSystemType = { "System.Int32", "System.Int32", "System.Single", "System.Boolean","System.Char" };

<<<<<<< .mine
        static private string[] m_arrType = { "int", "int", "float", "bool" ,"char"};
=======
        static private string[] m_arrSystemType = { "System.Int32", "System.Int32", "System.Single", "System.Boolean" };

        static private string[] m_arrType = { "int", "int", "float", "bool" };
>>>>>>> .r17
        #endregion
        
        #region methods
        /// <summary>
        /// doi tu tap hop sang loai du lieu
        /// </summary>
        /// <param name="strSet">tap hop can anh xa sang loai du lieu</param>
        /// <returns>tra ve loai du lieu, hoac tra ve null neu khong tim thay</returns>
        static public string MappingSetToType(string strSet)
        {
            int i;
            for (i = 0; i < m_arrSet.Length; i++)
            {
                if (m_arrSet[i] == strSet)
                {
                    return m_arrType[i];
                }
            }
            return null;
        }

        /// <summary>
        /// anh xa tu tap hop vao kieu du lieu cua he thong
        /// </summary>
        /// <param name="strSet">ten cua tap hop</param>
        /// <returns></returns>
        static public string MappingSetToSystemType(string strSet)
        {
            int i;
            for (i = 0; i < m_arrSet.Length; i++)
            {
                if (m_arrSet[i] == strSet)
                {
                    return m_arrSystemType[i];
                }
            }
            return null;
        }

        /// <summary>
        /// doi tu loai du lieu sang tap hop
        /// </summary>
        /// <param name="strType">loai du lieu can danh xa</param>
        /// <returns>tra ve loai tap hop, hoac tra ve null neu khong tim thay</returns>
        static public string MappingTypeToSet(string strType)
        {
            int i;
            for (i = 0; i < m_arrType.Length; i++)
            {
                if (m_arrType[i] == strType)
                {
                    return m_arrSet[i];
                }
            }
            return null;
        }

        static public string GetSystemType(string s)
        {
            s = s.ToLower();
            
            switch (s)
            {                    
                case"string":
                    return "System.String";
                case"int":
                    return "System.Int32";
                case"float":
                    return "System.Single";
                case"bool":
                    return "System.Boolean";
                case"long":
                    return "System.Int64";
                case"double":
                    return "System.Double";
                case"short":
                    return "System.Int16";
                default:
                    return null;
            }
        }
        #endregion
    }
}
